﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Reflection;
using System.Text;
using Demo.Common;

namespace Demo.BLL
{
    /// <summary>
    ///微信会员主表
    /// </summary>
    public partial class weixin_user
    {
        private readonly Model.sysconfig sysConfig = new BLL.sysconfig().loadConfig();//获得系统配置信息
        private readonly DAL.weixin_user dal;

        public weixin_user()
        {
            dal = new DAL.weixin_user(sysConfig.sysdatabaseprefix);
        }

        #region 基本方法================================
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int id)
        {
            return dal.Exists(id);
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public int Add(Model.weixin_user model)
        {
            return dal.Add(model);
        }

        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(Model.weixin_user model)
        {
            return dal.Update(model);
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        public bool Delete(int id)
        {
            return dal.Delete(id);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.weixin_user GetModel(int id)
        {
            return dal.GetModel(id);
        }

        /// <summary>
        /// 获得前几行数据
        /// </summary>
        public DataSet GetList(int Top, string strWhere, string filedOrder)
        {
            return dal.GetList(Top, strWhere, filedOrder);
        }

        /// <summary>
        /// 获得查询分页数据
        /// </summary>
        public DataSet GetList(int pageSize, int pageIndex, string strWhere, string filedOrder, out int recordCount)
        {
            return dal.GetList(pageSize, pageIndex, strWhere, filedOrder, out recordCount);
        }
        #endregion

        #region 扩展方法================================
        /// <summary>
        /// 检查用户表某一字段值是否存在（例如：检查用户名或者openid是否存在）
        /// </summary>
        public bool Exists(string field_name, string field_value)
        {
            return dal.Exists(field_name, field_value);
        }

        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public Model.weixin_user GetModel(string openid)
        {
            return dal.GetModel(openid);
        }

        /// <summary>
        /// 根据手机号得到一个对象实体
        /// </summary>
        public Model.weixin_user GetModelByMobile(string mobile)
        {
            return dal.GetModelByMobile(mobile);
        }

        /// <summary>
        /// 返回一个随机用户名
        /// </summary>
        public string GetRandomName(int length)
        {
            string temp = Utils.Number(length, true);
            if (Exists("user_name", temp))
            {
                return GetRandomName(length);
            }
            return temp;
        }

        /// <summary>
        /// 修改一列数据
        /// </summary>
        public int UpdateField(int id, string strValue)
        {
            return dal.UpdateField(id, strValue);
        }

        /// <summary>
        /// 修改一列数据
        /// </summary>
        public int UpdateField(string openid, string strValue)
        {
            return dal.UpdateField(openid, strValue);
        }
        #endregion

    }
}
